package cn.v2tila.rsosa.student.service.serviceImpl;

import cn.v2tila.rsosa.student.entity.UserEntity;
import cn.v2tila.rsosa.student.jpa.UserJPA;
import cn.v2tila.rsosa.student.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

/**
 * @author v2tila on 18:24 2019/2/22
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserJPA userJPA;

    public UserEntity findByOpenid(String openid) {

        return userJPA.findByOpenid(openid);
    }

    public UserEntity saveAndFlush(UserEntity userEntity) {

         return userJPA.saveAndFlush(userEntity);

    }

    public boolean existsByUniqueId(String uniqueId) {
        return userJPA.existsByUniqueId(uniqueId);
    }

    @Override
    public UserEntity findByUniqueId(String uniqueId) {
        return userJPA.findByUniqueId(uniqueId);
    }

    @Override
    public void deleteUser(UserEntity userEntity) {
            userJPA.delete(userEntity);
    }

    public Page<UserEntity> findAll(Example<UserEntity> example, Pageable pageable){
        return userJPA.findAll(example, pageable);
    }

}
